/*
//############################################################################################################
//#                                                                                                          #   
//#	The page gives admin the functionality to View/Add/Edit/Delete the registered admin users.               #
//# The data will be used from the 'tbl_Admin' table.                                                        #
//#         	                                                                                             #  
//#	Author: Naresh Pandey                                                                                    #
//#	Date: 18/02/06                                                                                           #
//#	                                                                                                         #
//	##########################################################################################################
*/



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using SiteManager;

public partial class Admin_Ad_ManageUser : System.Web.UI.Page
{// creating an instance of manager class
    Manager manager = new Manager(true,"ConnectionString");
    protected void Page_Load(object sender, EventArgs e)
    {
        BindGrid();
        string js = @"<script language=JavaScript> function ConfirmDeletion(){ return confirm('Are you sure you wish to delete Lead?');}</script>";
        if (!ClientScript.IsClientScriptBlockRegistered("ConfirmDeletion"))
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"ConfirmDeletion", js);
        }
        //dg_Member.PageSize = Convert.ToInt32(Session["AdminPageSize"]);        
    }

    /// <summary>
    ///  bind the grid view
    /// </summary>
    private void BindGrid()
    {
        string str = "";
        if (Session["ADMIN_ID"].ToString() != "1")
            str = "select * from tbl_admin where adminid<>1";
        else
            str = "select * from tbl_admin";
         DataSet ds = manager.ExecuteQuery(str, "tbl_");        
        if (!(ds.Tables[0].Rows.Count <= 0))
        {
            dg_Member.DataSource = ds;
            dg_Member.PageSize = Convert.ToInt32(Session["AdminPageSize"]);    
            dg_Member.DataBind();
            
            dg_Member.Visible = true;
        }
        else
        {
            dg_Member.Visible = false;
        }
    }
    // delete confiramtion
    protected void dg_Member_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowType == DataControlRowType.DataRow)
        {            
            e.Row.Cells[4].Attributes.Add("onClick", "return ConfirmDeletion();");
//            e.Row.Cells[3].Text = (e.Row.Cells[1].Text.Trim() != "1") ? "<a class='linkblue_10' href='Ad_User.aspx?uid=" + e.Row.Cells[1].Text + "'>" + e.Row.Cells[3].Text + "</a>" : e.Row.Cells[3].Text;            

            if (dg_Member.DataKeys[e.Row.RowIndex].Value.ToString()  == "1" || dg_Member.DataKeys[e.Row.RowIndex].Value.ToString()==Session["Admin_id"].ToString())
            {
                e.Row.Cells[4].Visible = false;
            }            
        }
    }

    // delete the user
    protected void dg_Member_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string del = "delete from tbl_Admin where adminid='" + dg_Member.DataKeys[e.RowIndex].Value + "'";   
			manager.ExecuteUpdate(del);
			BindGrid();
    }

    // paging
    protected void dg_Member_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        dg_Member.PageIndex = e.NewPageIndex;
        BindGrid();
    }
}
